package com.qf.vo;

import com.qf.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 返回结果通用类
 * @USER: Administrator
 * @DATE: 2025/9/2 下午9:29
 * @VERSION: 1.0.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVO<T> {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 是否成功
     */
    private Boolean success;

    /**
     * 返回数据
     */
    private T data;

    public ResultVO(ResultEnum resultEnum){
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMessage();
        this.success = resultEnum.isSuccess();
    }

    public ResultVO(ResultEnum resultEnum,String message){
        this.code = resultEnum.getCode();
        this.message = message;
        this.success = resultEnum.isSuccess();
    }

    public ResultVO(ResultEnum resultEnum,T data){
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMessage();
        this.success = resultEnum.isSuccess();
        this.data = data;
    }

    public static <T> ResultVO<T> success(){
        return new ResultVO<>(ResultEnum.SUCCESS);
    }

    public static <T> ResultVO<T> success(T data){
        return new ResultVO<>(ResultEnum.SUCCESS,data);
    }

    public static <T> ResultVO<T> fail(String message){
        return new ResultVO<>(ResultEnum.FAIL,message);
    }

}
